<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *空调管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'edit','title'=>'新建建筑类型'),	
);
$onepluginname='jy_kongtiaoshop';
//空调分类
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$tip='[温馨提示]：不同建筑，单位面积的冷负荷估算指标！';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_kongtiaoshop_home_type',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'建筑类型列表'),
			array('op'=>'edit','title'=>'添加类型'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'tip'=>$tip,'edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'image','title'=>'建筑图片','type'=>'image'),
			array('name'=>'title','title'=>'建筑类型名称','type'=>'string'),
			array('name'=>'wfee1','title'=>'冷负荷指标下','type'=>'unitstring','unit'=>'W'),
			array('name'=>'wfee2','title'=>'冷负荷指标上','type'=>'unitstring','unit'=>'W'),
		),'batch'=>array(
			array('type'=>'post','url'=>'/home_type/updata/','title'=>'同步建筑类型'),
		)),
		'search_one'=>array('name'=>'title','title'=>'建筑类型名称','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kongtiaoshop_home_type',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'paixu','title'=>'排序','type'=>'string'),	
					array('name'=>'title','title'=>'分类名称','type'=>'string','must'=>true),
					array('name'=>'image','title'=>'建筑图片','type'=>'image'),
					array('name'=>'wfee1','title'=>'冷负荷指标下','type'=>'unitstring','unit'=>'W'),
					array('name'=>'wfee2','title'=>'冷负荷指标上','type'=>'unitstring','unit'=>'W'),
				)),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('标题不能为空','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'image'=>trim($postdata['image']),
		'wfee1'=>intval($postdata['wfee1']),
		'wfee2'=>intval($postdata['wfee2']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_kongtiaoshop_home_type',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{	
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_kongtiaoshop_home_type',$data);
		$insertid=pdo_insertid();
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='updata'){
	$list=$this->model('model')->apihometypes();
	foreach($list as $item){
		$isadd=pdo_get('jy_kongtiaoshop_home_type',array('title'=>$item['title'],'uniacid'=>$_SESSION['uniacid']));
		if(!$isadd){
			$data=array(
				'title'=>trim($item['title']),
				'wfee1'=>intval($item['wfee1']),
				'wfee2'=>intval($item['wfee2']),
			);
			$data['uniacid']=$_SESSION['uniacid'];
			pdo_insert('jy_kongtiaoshop_home_type',$data);
		}
	}
	exi('同步成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_kongtiaoshop_home_type',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}